package itsm.isperp.workflow.graph;

/**
 * 
 * 
 * @author lizx
 * @date 2013-4-24
 */
public class Shape {

	private float x;
	private float y;
	private float w;
	private float h;
	private String name;
	private DirEnum dir;
	private float offset;
	private float fHOffset;
	private float fVOffset;

	public Shape(String name, float x, float y, float w, float h) {
		this.x = 0.0F;
		this.y = 0.0F;
		this.w = 0.0F;
		this.h = 0.0F;
		this.name = "";
		offset = 0.0F;
		fHOffset = 0.0F;
		fVOffset = 0.0F;
		this.h = h;
		if (name.equals("bg:StartEvent") || name.equals("bg:EndEvent"))
			this.h = w;
		this.name = name;
		this.x = x;
		this.y = y;
		this.w = w;
	}

	public float getOffset() {
		return offset;
	}

	public void setOffset(float offset) {
		this.offset = offset;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setDirectory(String dirx, String diry) {
		if (!dirx.equals("")) {
			if (dirx.equals("0"))
				dir = DirEnum.Left;
			if (dirx.equals("1"))
				dir = DirEnum.Right;
		}
		if (!diry.equals("")) {
			if (diry.equals("0"))
				dir = DirEnum.Top;
			if (diry.equals("1"))
				dir = DirEnum.Bottom;
		}
	}

	public DirEnum getDirectory() {
		return dir;
	}

	public void setHV(String hOffset, String vOffset) {
		if (!hOffset.equals(""))
			fHOffset = Float.parseFloat(hOffset);
		if (!vOffset.equals(""))
			fVOffset = Float.parseFloat(vOffset);
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

	public float getW() {
		return w;
	}

	public void setW(float w) {
		this.w = w;
	}

	public float getH() {
		return h;
	}

	public void setH(float h) {
		this.h = h;
	}

	public Point getTopCenter() {
		float tmpx = x + w / 2.0F;
		Point p = new Point(tmpx, y);
		setHV(p);
		return p;
	}

	public Point getLeftCenter() {
		float tmpy = y + h / 2.0F;
		Point p = new Point(x, tmpy);
		setHV(p);
		return p;
	}

	public Point getBottomCenter() {
		float tmpx = x + w / 2.0F;
		float tmpy = y + h;
		Point p = new Point(tmpx, tmpy);
		setHV(p);
		return p;
	}

	public Point getRightCenter() {
		float tmpx = x + w;
		float tmpy = y + h / 2.0F;
		Point p = new Point(tmpx, tmpy);
		setHV(p);
		return p;
	}

	public Point getPoint() {
		Point p;
		if (dir == DirEnum.Top)
			p = getTopCenter();
		else if (dir == DirEnum.Bottom)
			p = getBottomCenter();
		else if (dir == DirEnum.Left)
			p = getLeftCenter();
		else
			p = getRightCenter();
		return p;
	}

	private void setHV(Point p) {
		p.setX(p.getX() + fHOffset);
		p.setY(p.getY() + fVOffset);
	}

}
